<template>
  <div>
    <el-row :gutter="10" style="margin-bottom: 60px">
      <el-col :span="6">
        <el-card style="color: #409EFF">
          <div><i class="el-icon-user-solid" /> 用户总数</div>
          <div style="padding: 10px 0; text-align: center; font-weight: bold">
            {{ user_total }}
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #F56C6C">
          <div><i class="el-icon-money" /> 销售总量</div>
          <div style="padding: 10px 0; text-align: center; font-weight: bold">
            {{ totalOrder }}
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #67C23A">
          <div><i class="el-icon-bank-card" /> 收益总额</div>
          <div style="padding: 10px 0; text-align: center; font-weight: bold">
            ￥ {{totalPrice}}
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #E6A23C">
          <div><i class="el-icon-s-shop" /> 门店总数</div>
          <div style="padding: 10px 0; text-align: center; font-weight: bold">
            {{totalShop}}
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <div id="main" style="width: 500px; height: 450px"></div>
      </el-col>

      <el-col :span="12">
        <div id="pie" style="width: 500px; height: 400px"></div>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: "Home",
  data() {
    return {
      user_total: 0,
      totalPrice: 0,
      totalOrder: 0,
      totalShop: 0,
    }
  },
  methods: {
    getUserTotal() {
      this.request.get("/user/data/userTotal").then(res => {
        this.user_total = res.data;
      })
    },
    getTotalOrder() {
      this.request.get("/user/data/orderTotal").then(res => {
        this.totalOrder = res.data;
      })
    },
    getTotalPrice() {
      this.request.get("/user/data/priceTotal").then(res => {
        this.totalPrice = res.data;
      })
    },
    getTotalShop() {
      this.request.get("/user/data/venueTotal").then(res => {
        this.totalShop = res.data;
      })
    }
  },
  mounted() {
    // 页面元素渲染之后再触发
    this.getUserTotal();
    this.getTotalOrder();
    this.getTotalPrice();
    this.getTotalShop();

    var option = {
      title: {
        text: '各季度会员数量统计',
        subtext: '趋势图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      xAxis: {
        type: 'category',
        data: ["第一季度", "第二季度", "第三季度", "第四季度"]
      },
      yAxis: {
        type: 'value'
      },
      series: [{
        name: "新用户",
        data: [120, 132, 101, 134],
        type: 'bar'
      },
        {
          name: "新用户",
          data: [120, 132, 101, 134],
          type: 'line'
        },
        {
          name: "续费用户",
          data: [220, 182, 191, 234],
          type: 'bar'
        },
        {
          name: "续费用户",
          data: [220, 182, 191, 234],
          type: 'line'
        }
      ]
    };

    // 饼图
    var pieOption = {
      title: {
        text: '各季度会员数量统计',
        subtext: '比例图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item',
        formatter: '{a} <br/>{b} : {c} ({d}%)'
      },
      legend: {
        orient: 'vertical',
        left: 'left',
        data: ['续费用户', '新用户']
      },
      series: [{
        name: "续费用户",
        type: 'pie',
        radius: '55%',
        center: ['25%', '70%'],
        label: {
          //饼图图形上的文本标签
          normal: {
            show: true,
            position: 'inner',
            //标签的位置
            textStyle: {
              fontWeight: 300,
              fontSize: 14,
              //文字的字体大小
              color: "#000000"
            },
            formatter: '{c}({d}%)'
          }
        },
        data: [{
          name: "第一季度",
          value: 220
        },
          {
            name: "第二季度",
            value: 182
          },
          {
            name: "第三季度",
            value: 191
          },
          {
            name: "第四季度",
            value: 234
          }
        ],
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      },
        {
          name: "新用户",
          type: 'pie',
          radius: '50%',
          center: ['75%', '50%'],
          label: {
            //饼图图形上的文本标签
            normal: {
              show: true,
              position: 'inner',
              //标签的位置
              textStyle: {
                fontWeight: 300,
                fontSize: 14,
                //文字的字体大小
                color: "#000000"
              },
              formatter: '{d}%'
            }
          },
          data: [{
            name: "第一季度",
            value: 120
          },
            {
              name: "第二季度",
              value: 132
            },
            {
              name: "第三季度",
              value: 101
            },
            {
              name: "第四季度",
              value: 134
            }
          ],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ],
    };

    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    var pieDom = document.getElementById('pie');
    var pieChart = echarts.init(pieDom);

    // 直接使用死数据显示图表
    myChart.setOption(option);
    pieChart.setOption(pieOption);
  }
}
</script>


<style scoped>

</style>